package javaRew;

import java.util.Date;

import static javaRew.Person2.total;

/**
 * Created by xjweng on 2017/1/30.
 */
public class TestPerson2 {
    public static void main(String[] args){
        /**
         * 多态测试
         */
        Person2 per_4 = new Person2();
        Person2 per_3 = new Man();
        Person2 per_5 = new Women();
        //虚拟方法调用,用Man的getInfo方法，方法调用是运行时确定的——动态绑定
        System.out.println(per_3.getInfo());
        Man man_1 = (Man) per_3;  //强制类型转换
        //per_5是Women类实例，抛出类型转换异常
        //Man man_2 = (Man) per_5;
        /**
         * 避免配型转换异常 用instanceof判断
         */
        System.out.println(per_3 instanceof Person2);
        /**
         * 静态static测试
         */
        Person2 per_6 = new Person2();
        //Person2.total : 不用创建对象就可以访问静态成员
        // 不用创建对象就可以访问静态成员
        System.out.println("per_6's total: " + total);
        Person2 per_7 = new Person2();
        System.out.println("per_7's id: " + per_7.getId());

        //没有对象的实例时，可以用类名.方法名()的形式访问由static标记的类方法
        System.out.println("Totals: " + Person2.getTotal());

        /**
         * 继承测试
         */
        Student stu_1 = new Student();
        stu_1.age = 18;
        stu_1.birth = new Date();
        stu_1.name = "stu001";
        stu_1.school = "scut";
        System.out.println(stu_1.getInfo());

        Person2 per_2 = new Person2();
        per_2.age = 1;
        per_2.birth = new Date();
        per_2.name = "SecondOne";
        System.out.println(per_2.getInfo());
    }
}
